import java.util.ArrayList;
/**
 * Created with IntelliJ IDEA.
 * User: Alex
 * Date: 12.06.13
 * Time: 23:02
 * To change this template use File | Settings | File Templates.
 */
public class Essence {
    private ArrayList<Animal> essen;
    private int widthSpace;
    private int lengthSpace;
             Essence(int widthSpace, int lengthSpace) {
                this.widthSpace = widthSpace;
                 this.lengthSpace = lengthSpace;
                 essen = new ArrayList<Animal>();
             }

    public Animal get(int index) {
        return essen.get(index);
    }

    public void burnEssence(String type, int number) {
        for (int essence = 0;essence < number;essence++) {
            if (type == "Tiger") {
                essen.add(new Tiger(widthSpace, lengthSpace));
            } else if (type == "Rabbit") {
                essen.add(new Rabbit(widthSpace, lengthSpace));
            }
        }
    }

    public void moveAllSubjectInDesert() {
        moveRabbit();
        moveTigers();
    }

    public void moveTigers() {
        for (Animal subject: essen) {
            if (subject instanceof Tiger) {
                findNearestVictim(subject.getPossition());
                subject.move();
            }
        }
    }

    public void moveRabbit() {
        for (Animal subject: essen) {
            if (subject instanceof Rabbit) {
                subject.move();
            }
        }
    }

    public void findNearestVictim(Position position) {
        int stepsBetweenObject = 100;
        int number;
        for (int animals = 0;animals < essen.size();animals++) {
            if (essen.get(animals) instanceof Rabbit) {
                if (countStepsBetweenObject(position,essen.get(animals).getPossition()) < stepsBetweenObject) {
                    number = animals;
                }
            }
        }

    }

    public int countStepsBetweenObject(Position position1,Position position2) {
        if (position1.getPosition("X") < position2.getPosition("Y")) {

        }
        return 100;
    }

}
